import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

/**
 * @Author 12629
 * @Description：
 */
public class Test {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()) {
            int N = scan.nextInt();
            int f1 = 0;
            int f2 = 1;
            int f3 = -1;
            while(f3 < N) {
                f3 = f1+f2;
                if(f3 >= N) {
                    break;
                }
                f1 = f2;
                f2 = f3;
            }
            if(Math.abs(f3-N) < Math.abs(f2-N)) {
                System.out.println(Math.abs(f3-N));
            }else {
                System.out.println(Math.abs(f2-N));
            }
        }
    }

    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        HashSet<String> set = new HashSet<>();
        while(scan.hasNextLine()) {
            String str = scan.nextLine();
            String[] strings = str.split(" ");
            for(String s : strings) {
                set.add(s);
            }
        }
        System.out.println( set.size());
    }
}
